package woshiheima10;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/*
客服端：发送数据，接收服务器反馈
 */
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //创建socket对象
        Socket s =new Socket("192.168.0.107",10086);

        //获取输出流写数据
        OutputStream os = s.getOutputStream();
        os.write("hello,tcp,我来了".getBytes());

        //接受服务器反馈
        InputStream is = s.getInputStream();

        byte[] bys = new byte[1024];//通过字节数组读取
        int len = is.read(bys);
        String data = new String(bys,0,len);
        System.out.println("客服端："+data);

        //释放资源
        s.close();

    }
}
